/*
 * MinIO Cloud Storage (C) 2018 MinIO, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import React from "react"
import classNames from "classnames"
import { connect } from "react-redux"
import axios from "axios"
import TopBar from "./TopBar"
import FileContent from "./FileContent"
import FileDetail from "./FileDetail"
import AlertContainer from "../alert/AlertContainer"
import Alert from "../alert/Alert"
import * as actionsAlert from "../alert/actions"
import web from "../web"
import storage from 'local-storage-fallback'

class FilePage extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      fileState: false
    }
  }
  componentWillUnmount() {
    
    // web.RedisAClSetUser({
    //   username: storage.getItem('uname'),
    //   password: storage.getItem('pwd')
    // }).then(res => {
    //   console.log(res.message)
    // })
  }
  componentDidMount() {
    // const { showAlert, clearAlert } = this.props
    // storage.setItem('fileState', false)
    
    // axios({
    //   method: 'post',
    //   url: "http://192.168.0.29:1323/filelist",
    //   headers: {'Content-Type': 'application/json','Access-Control-Allow-Origin':'*'},
    //   data: {
    //     username: storage.getItem('uname'),
    //     password: storage.getItem('pwd')
    //   }
    // })
    // .then(
    //   (response)=>{
    //     const { showAlert, clearAlert } = this.props
    //     let message = ""
    //     if (response.data == "key does not exist"){
    //       console.log(response.data)
    //       this.setState({
    //         fileState: false,
    //       })
    //       message = response.data
    //       showAlert("success", message)
    //     }else {
    //       if(response.data.Name != ""){
    //         this.setState({
    //           fileState: true,
    //         })
    //       }else{
    //         this.setState({
    //           fileState: false,
    //         })
    //       }
    //     }
    //   }
    //   )
    //   .catch(
    //     (error)=>{
    //       // const { showAlert, clearAlert } = this.props
    //       // showAlert("danger", error)
    //       console.log(error)
    //   }
    // )
  }

  render() {
    return (
      <div
      className={classNames({
        "file-explorer": true
      })}
      >
        <TopBar/>
        {/* {this.state.fileState ? (
          <FileDetail />
        ):( */}
          <FileContent />
        {/* )} */}
        <AlertContainer />
      </div>
    )
  }
}
const mapDispatchToProps = dispatch => {
  return {
    showAlert: (type, message) =>
      dispatch(actionsAlert.set({ type: type, message: message })),
    clearAlert: () => dispatch(actionsAlert.clear())
  }
}
export default connect(
  state => state,
  mapDispatchToProps
)(FilePage)
